package com.hongyuan.venue.ui.person.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.venue.R;
import com.hongyuan.venue.base.AppViewModelFactory;
import com.hongyuan.venue.base.CustomFragment;
import com.hongyuan.venue.data.Constants;
import com.hongyuan.venue.databinding.FragmentMyCouponBinding;
import com.hongyuan.venue.ui.person.view_mode.MyCouponViewModel;

import me.tatarka.bindingcollectionadapter2.BR;

public class MyCouponFragment extends CustomFragment<FragmentMyCouponBinding, MyCouponViewModel> {

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_my_coupon;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public MyCouponViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(MyCouponViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();
        setOnRefresh(binding.refresh,REFRESH_0X3);
        setEnableLoadMore(Constants.MY_COUPON_LIST);
        setEnableRefresh(Constants.MY_COUPON_LIST);
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.clearParams().setParams("coupon_way","2").setParams("os_id","");
        if("0".equals(getPosition())){
            viewModel.setParams("is_use","2");
        }else if("1".equals(getPosition())){
            viewModel.setParams("is_use","1");
        }else{
            viewModel.setParams("is_exp","1");
        }
    }

}
